<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Home\Model\CosSimilarityModel;
class IndexController extends InitializeController {
    public function index(){
//        $cos = new CosSimilarityModel();
//        $cos->cosine();
//        die;
        header("Content-Type:text/html;charset=utf-8");
    	$db = M('Product');
    	$this->top = M('Menu')->where('top=1')->select();
    	
    	$leftLevel1 = M('Menu')->where('top!=1 and level=1')->order('id asc')->select();
      
        $this->carCount = $this->carCount();

        foreach ($leftLevel1 as $k => $v) {
            $where['pid'] = $v['id'];
            $group[] = M('Menu')->where($where)->select();
        }

        $recommend = D('Recommend');
        $recd = $recommend->getRecommend();
        $rand = $recommend->numberRand();
        //推荐五件商品
        unset($recommend);
        foreach ($rand as $k => $v){
            $recommend[] = $recd[$v];
            $recommend[$k]['id'] += $v+1;
        }

    	//lastIntership_tp
    	// $this->hot = $db->limit(0,8)->select();
        $this->assign('leftLevel1',$leftLevel1);
    	$this->assign('group',$group);
    	$this->assign('recommend',$recommend);
        $this->display();
    }

    public function carCount(){
        $db = M('prod_user');
        $allCount = 0;
        $count = $db->where("user_id=%d",$_SESSION['mallUserId'])->field('count')->select();
        foreach ($count as $v) {
            $allCount += $v['count'];
        }
        return $allCount;
    }

    public function pri($data)
    {
        echo '<pre>';
        print_r($data);
        echo '</pre>';
    }
}